//
//  KABMallMyOrderVC.m
//  kabu
//
//  Created by XiangDongMBP on 2017/2/20.
//  Copyright © 2017年 East. All rights reserved.
//

#import "KABMallMyOrderVC.h"
#import "KABMallMyOrdHeaderCCell.h"
#import "KABMallShopCartTCell.h"
#import "KABMallShoCarHeaderHFView.h"
#import "KABMallSurOrdFooterHFView.h"
#import "KABMallOrderDetailVC.h"
#import <MJRefresh.h>
#import "XDAFNetworking.h"
#import "GlobalHeader.h"
#import "ApiManager.h"
#import "KABModel.h"
#import "MBProgressHUD+XDPrompt.h"
#import <UIScrollView+EmptyDataSet.h>
#import "KABMallLogisticVC.h"
#import "WXApiManager.h"
#import "KABMallReturnProVC.h"

@interface KABMallMyOrderVC ()<UITableViewDelegate, UITableViewDataSource, UICollectionViewDelegate, UICollectionViewDataSource, DZNEmptyDataSetDelegate, DZNEmptyDataSetSource, KABMallSurOrdFooterHFViewDelegate, WXApiManagerDelegate>

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (strong, nonatomic) MJRefreshNormalHeader *mj_header;
@property (strong, nonatomic) MJRefreshAutoNormalFooter *mj_footer;

@property (strong, nonatomic) NSArray<NSString *> *titlesArray;
@property (strong, nonatomic) NSArray<NSNumber *> *typeIndexArray;
@property (strong, nonatomic) KABMallOrderList *orderList;

@property (strong, nonatomic) KABMallOrderDetail *orderDetail;  //!< 标记正在支付的订单
@property (strong, nonatomic) KABMallSubOrdBackModel *tempOrder;//!< 支付中间用于查询的临时数据

@property (assign, nonatomic) BOOL refreshFlag;//!< 刷新界面的标记(用于从详情页面返回时是否刷新的标记)

@end

static NSString *const kCollectionViewHeaderCellId = @"KABMallMyOrdHeaderCCell";

static NSString *const kReuseCellId = @"KABMallShopCartTCell";
static NSString *const kHeaderViewId = @"KABMallShoCarHeaderHFView";
static NSString *const kFooterViewId = @"KABMallSurOrdFooterHFView";
static NSInteger const kRequestUserSize = 20;

@implementation KABMallMyOrderVC

#pragma mark - life cycle
- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // 添加通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidBecomeActiveHandle:) name:UIApplicationDidBecomeActiveNotification object:nil];
    
    [self initNavigationBar];
    [self initSubViews];
}

- (void)initNavigationBar {
    self.navigationItem.title = @"我的订单";
}

- (BOOL)hidesBottomBarWhenPushed {
    return YES;
}

- (void)initSubViews {
        self.automaticallyAdjustsScrollViewInsets = NO;
    //
    //    self.tableView.contentInset = UIEdgeInsetsMake(-64 * 2.0, 0, 49.0, 0);
    //    self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(64, 0, 49.0, 0);
    
    UINib *cvCellNib = [UINib nibWithNibName:kCollectionViewHeaderCellId bundle:nil];
    [self.collectionView registerNib:cvCellNib forCellWithReuseIdentifier:kCollectionViewHeaderCellId];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    
    UINib *headerNib = [UINib nibWithNibName:kHeaderViewId bundle:nil];
    [self.tableView registerNib:headerNib forHeaderFooterViewReuseIdentifier:kHeaderViewId];
    UINib *footerNib = [UINib nibWithNibName:kFooterViewId bundle:nil];
    [self.tableView registerNib:footerNib forHeaderFooterViewReuseIdentifier:kFooterViewId];
    UINib *cellNib = [UINib nibWithNibName:kReuseCellId bundle:nil];
    [self.tableView registerNib:cellNib forCellReuseIdentifier:kReuseCellId];
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight = 44.0;
    self.tableView.sectionHeaderHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedSectionHeaderHeight = 48.0;
    self.tableView.sectionFooterHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedSectionFooterHeight = 108.0;
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.emptyDataSetDelegate = self;
    self.tableView.emptyDataSetSource = self;
    
    // 下拉刷新
    self.tableView.mj_header = self.mj_header;
    self.tableView.mj_footer = self.mj_footer;
    
    [self.tableView.mj_header beginRefreshing];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    // 选中title的某一项
    NSUInteger item = [self.typeIndexArray indexOfObject:@(self.orderType)];
    NSIndexPath *indexPath = [NSIndexPath indexPathForItem:item inSection:0];
    [self.collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone];
    
    if (self.refreshFlag) {
        self.refreshFlag = NO;
        [self.tableView.mj_header beginRefreshing];
    }
}

#pragma mark - DZNEmptyDataSetSource
- (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView {
    NSDictionary *dic = @{NSFontAttributeName : [UIFont systemFontOfSize:14.0]};
    return [[NSAttributedString alloc] initWithString:@"您还没有相关的订单" attributes:dic];
}

- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
    return [KABDefaultVarModel sharedInstance].bitmapDefaultImg;
}

//- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
//    return -50.0;
//}

#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.titlesArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    KABMallMyOrdHeaderCCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCollectionViewHeaderCellId forIndexPath:indexPath];
    cell.titleLabel.text = self.titlesArray[indexPath.row];
//    NSInteger type = [self.typeIndexArray[indexPath.item] integerValue];
//    cell.selected = (type == self.orderType);
    return cell;
}

#pragma mark - <UICollectionViewDelegateFlowLayout>
//- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
//    return CGSizeMake(CGRectGetWidth(self.view.bounds), 110.0);
//}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    NSInteger cnt = self.titlesArray.count;
    CGFloat width = (CGRectGetWidth(self.view.bounds) - 2*13 - (cnt - 1) * 10) / cnt;
//    CGFloat height = width * 133.0 / 100.0;
    return CGSizeMake(width, 40.0);
}

#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSInteger type = [self.typeIndexArray[indexPath.item] integerValue];
    self.orderType = type;
    [self.tableView.mj_header beginRefreshing];
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.orderList.order_list.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    KABMallOrderDetail *item = self.orderList.order_list[section];
    return item.product_list.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    KABMallShopCartTCell *cell = [tableView dequeueReusableCellWithIdentifier:kReuseCellId forIndexPath:indexPath];
    if (indexPath.section < self.orderList.order_list.count) {
        KABMallOrderDetail *item = self.orderList.order_list[indexPath.section];
        if (indexPath.row < item.product_list.count) {
            [cell configViewWithOrderProItem:item.product_list[indexPath.row] couldSel:NO isEdit:NO];
        }
    }
    return cell;
}

#pragma mark - UITableViewDelegate
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    KABMallShoCarHeaderHFView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:kHeaderViewId];
    KABMallOrderDetail *item = self.orderList.order_list[section];
    [view configViewWithOrderDetail:item couldSel:NO wholeSel:NO];
    return view;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    KABMallSurOrdFooterHFView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:kFooterViewId];
    if (section < self.orderList.order_list.count) {
        [view configViewWithOrderDetail:self.orderList.order_list[section]];
    }
    view.section = section;
    view.delegate = self;
    return view;
}
//- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
//    return 0.1;
//}
//
//- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
//    return 6.0;
//}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    KABMallOrderDetailVC *vc = [[KABMallOrderDetailVC alloc] init];
    vc.orderDetail = self.orderList.order_list[indexPath.section];
    vc.userDoActionHandle = ^(){
        self.refreshFlag = YES;
    };
    [self showViewController:vc sender:nil];
}

#pragma mark - KABMallSurOrdFooterHFViewDelegate
- (void)kABMallSurOrdFooterHFView:(KABMallSurOrdFooterHFView *)view section:(NSInteger)section leftBtnTapped:(UIButton *)btn {
    KABMallOrderDetail *detail = self.orderList.order_list[section];
    if ([[btn titleForState:UIControlStateNormal] isEqualToString:@"查看物流"]) {
        KABMallLogisticVC *vc = [[KABMallLogisticVC alloc] init];
        vc.logistic_code = detail.logistic_code;
        [self showViewController:vc sender:nil];
    }
}
- (void)kABMallSurOrdFooterHFView:(KABMallSurOrdFooterHFView *)view section:(NSInteger)section rightBtnTapped:(UIButton *)btn {
    KABMallOrderDetail *detail = self.orderList.order_list[section];
    if (detail.order_type == 1) {       // 请求微信支付
        self.orderDetail = detail;
        [self requestWxPay:detail];
        return;
    } else if (detail.order_type == 2) {// 催促发货
        [MBProgressHUD showPromptWithAutoHideInView:self.view message:@"已催促店家尽快发货"];
        return;
    } else if (detail.order_type == 3) {// 确认收货
        [self userConfirmOrder:detail];
        return;
    } else if (detail.order_type == 4) {// 申请退货
        KABMallReturnProVC *vc = [[KABMallReturnProVC alloc] init];
        vc.orderDetail = detail;
        vc.returnSucHandle = ^(){
            [self.tableView.mj_header beginRefreshing];
        };
        [self showViewController:vc sender:nil];
        return;
    }
}

#pragma mark - WXApiManagerDelegate
- (void)managerDidRecvPayResponse:(PayResp *)response {
    NSLog(@"微信支付返回：%d, %@, 响应类型:%d", response.errCode, response.errStr, response.type);
    NSLog(@"微信支付：财付通返回:%@", response.returnKey);
//    [self requestProOrderQueryWithOutTradeNo:self.tempOrder.out_trade_no];
}

#pragma mark - event response
- (void)appDidBecomeActiveHandle:(NSNotification *)notification {
    if (self.tempOrder) {;
        NSLog(@"请求微信支付结果");
        // 请求微信支付结果
        [self requestProOrderQueryWithOutTradeNo:self.tempOrder.out_trade_no];
    }
}

#pragma mark - private methods
- (void)payResultProcess {
    [self.tableView.mj_header beginRefreshing];
    [self jumpToOrderDetail:self.orderDetail];
}

- (void)jumpToOrderDetail:(KABMallOrderDetail *)orderDetail {
    KABMallOrderDetailVC *detailVC = [[KABMallOrderDetailVC alloc] init];
    detailVC.order_id = orderDetail.order_id;
    [self showViewController:detailVC sender:nil];
    self.orderDetail = nil;
    self.tempOrder = nil;
}

- (void)userConfirmOrder:(KABMallOrderDetail *)orderDetail {
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"确认已经收货了吗？" message:@"确认收货后，将打款给商家" preferredStyle:UIAlertControllerStyleAlert];
    [alertVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
    [alertVC addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self requestConfirmOrder:orderDetail];
    }]];
    [self presentViewController:alertVC animated:YES completion:nil];
}

- (void)refreshWholeView {
    // 尾部加载更多的显示
    if (self.orderList.totalLoad) {
        [self.tableView.mj_footer endRefreshingWithNoMoreData];
    } else {
        [self.tableView.mj_footer resetNoMoreData];
    }
    
    [self.tableView reloadData];
}

- (void)tableViewEndRefresh:(BOOL)isHeader {
    NSLog(@"停止刷新是否是头部---%zd", isHeader);
    if (isHeader) {
        [self.tableView.mj_header endRefreshing];
    } else {
        [self.tableView.mj_footer endRefreshing];
    }
}

- (void)tableViewRefresh:(id)sender {
    BOOL isHeader = [sender isKindOfClass:[MJRefreshHeader class]];
    [self requestUserListWithHeader:isHeader];
}

- (KABMallOrderList *)orderListWithDictionary:(NSDictionary *)dic isAddMore:(BOOL)AddMore {
    if ([dic[KABGlobalJsonKeyErrCode] integerValue] != 200) {
        return self.orderList;
    }
    
    KABMallOrderList *temp = [KABMallOrderList yy_modelWithDictionary:dic[KABGlobalJsonKeyResult]];
    if (!temp) {
        return self.orderList;
    }
    
    if (AddMore && self.orderList) {
        [self.orderList addMoreWithData:temp];
    } else {
        self.orderList = temp;
    }
    return self.orderList;
}

#pragma mark - network request
- (void)requestUserListWithHeader:(BOOL)isHeader {
    // 发布Cos需要登录
    if (![KABModel sharedInstance].isLogin) {
        [[NSNotificationCenter defaultCenter] postNotificationName:KABGlobalNotiUserTokenInvalid object:nil];
        [self tableViewEndRefresh:isHeader];
        return;
    }
    
    NSInteger startIndex = isHeader ? 0 : self.orderList.order_list.count;
    NSDictionary *pars = @{@"user_id" : @([KABModel sharedInstance].userInfo.uid),
                           @"access_token" : [KABModel sharedInstance].userInfo.access_token,
                           @"order_type" : @(self.orderType),
                           @"index" : @(startIndex),
                           @"size" : @(kRequestUserSize)};
    NSLog(@"请求订单列表的参数：%@", pars);
    [[XDAFNetworking sharedInstance] GET:[ApiManager apiProductOrderList] parameters:pars progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"请求订单列表返回：%@", responseObject);
        [self tableViewEndRefresh:isHeader];
        if ([responseObject[KABGlobalJsonKeyErrCode] integerValue] == 200) {
            [self orderListWithDictionary:responseObject isAddMore:!isHeader];
        } else {
            [MBProgressHUD showPromptWithAutoHideInView:self.view message:responseObject[KABGlobalJsonKeyMsg]];
        }
        [self refreshWholeView];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"请求订单列表失败：%@", error);
        [self tableViewEndRefresh:isHeader];
        [MBProgressHUD showPromptWithAutoHideInView:self.view message:@"网络请求失败"];
    }];
}

- (void)requestWxPay:(KABMallOrderDetail *)orderDetail {
    // 提示安装微信支付
    if (![WXApi isWXAppInstalled]) {
        [MBProgressHUD showPromptWithAutoHideInView:self.view message:@"需要安装微信才能支付"];
        return;
    }
    
    // 请求购物车必须要登录
    if (![KABModel sharedInstance].isLogin) {
        [[NSNotificationCenter defaultCenter] postNotificationName:KABGlobalNotiUserTokenInvalid object:nil];
        return;
    }
    
    MBProgressHUD *hud = [MBProgressHUD xd_showHUDAddedTo:self.view animated:YES];
    // 收藏请求
    NSDictionary *pars = @{@"user_id" : @([KABModel sharedInstance].userInfo.uid),
                           @"access_token" : [KABModel sharedInstance].userInfo.access_token,
                           @"order_list" : @[orderDetail.order_id]};
    [[XDAFNetworking sharedInstance] POST:[ApiManager apiWXPay] parameters:pars progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"提交订单返回：%@", responseObject);
        [hud hideAnimated:NO];
        if ([responseObject[KABGlobalJsonKeyErrCode] integerValue] == 200) {
            self.tempOrder = [KABMallSubOrdBackModel yy_modelWithDictionary:responseObject[KABGlobalJsonKeyResult]];
            [self callWx:self.tempOrder.wx_pay];
        } else {
            [MBProgressHUD showPromptWithAutoHideInView:self.view message:responseObject[KABGlobalJsonKeyMsg]];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [hud hideAnimated:NO];
        NSLog(@"提交订单失败：%@", error);
        [MBProgressHUD showPromptWithAutoHideInView:self.view message:@"网络请求失败"];
    }];
}

- (void)callWx:(KABMallWxPayPars *)wxPay {
    if (!wxPay) {
        [MBProgressHUD showPromptWithAutoHideInView:self.view message:@"微信支付参数错误"];
        return;
    }
    
    // 置位代理
    [WXApiManager sharedManager].delegate = self;
    
    PayReq *request = [[PayReq alloc] init];
    request.partnerId = wxPay.partnerId;
    request.prepayId= wxPay.prepayId;
    request.package = wxPay.package;
    request.nonceStr= wxPay.nonceStr;
    request.timeStamp= wxPay.timeStamp;
    request.sign= wxPay.sign;
    NSLog(@"请求参数:\n partnerId = %@ \n prepayId = %@ \n package = %@ \n nonceStr = %@ \n timeStamp = %zd \n sign = %@ ", request.partnerId, request.prepayId, request.package, request.nonceStr, request.timeStamp, request.sign);
    [WXApi sendReq:request];
}

- (void)requestConfirmOrder:(KABMallOrderDetail *)orderDetail {
    // 请求购物车必须要登录
    if (![KABModel sharedInstance].isLogin) {
        [[NSNotificationCenter defaultCenter] postNotificationName:KABGlobalNotiUserTokenInvalid object:nil];
        return;
    }
    
    MBProgressHUD *hud = [MBProgressHUD xd_showHUDAddedTo:self.view animated:YES];
    // 收藏请求
    NSDictionary *pars = @{@"user_id" : @([KABModel sharedInstance].userInfo.uid),
                           @"access_token" : [KABModel sharedInstance].userInfo.access_token,
                           @"order_id" : orderDetail.order_id};
    [[XDAFNetworking sharedInstance] POST:[ApiManager apiProConfirmOrder] parameters:pars progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"确认收货返回：%@", responseObject);
        [hud hideAnimated:NO];
        if ([responseObject[KABGlobalJsonKeyErrCode] integerValue] == 200) {
            [self.tableView.mj_header beginRefreshing];
        } else {
            ;
        }
        [MBProgressHUD showPromptWithAutoHideInView:self.view message:responseObject[KABGlobalJsonKeyMsg]];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [hud hideAnimated:NO];
        NSLog(@"确认收货失败：%@", error);
        [MBProgressHUD showPromptWithAutoHideInView:self.view message:@"网络请求失败"];
    }];
}
- (void)requestProOrderQueryWithOutTradeNo:(NSString *)out_trade_no {
    // 查询购买结果必须要登录
    if (![KABModel sharedInstance].isLogin) {
        [[NSNotificationCenter defaultCenter] postNotificationName:KABGlobalNotiUserTokenInvalid object:nil];
        return;
    }
    
    if (!out_trade_no.length) {
        [MBProgressHUD showPromptWithAutoHideInView:self.view message:@"订单号错误"];
        return;
    }
    
    MBProgressHUD *hud = [MBProgressHUD xd_showHUDAddedTo:self.view animated:YES];
    // 收藏请求
    NSDictionary *pars = @{@"user_id" : @([KABModel sharedInstance].userInfo.uid),
                           @"access_token" : [KABModel sharedInstance].userInfo.access_token,
                           @"out_trade_no" : out_trade_no};
    [[XDAFNetworking sharedInstance] POST:[ApiManager apiProductOrderQuery] parameters:pars progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"查询结果返回：%@", responseObject);
        [hud hideAnimated:NO];
        NSString *str = responseObject[KABGlobalJsonKeyMsg];
        if ([responseObject[KABGlobalJsonKeyErrCode] integerValue] == 200) {
            NSDictionary *dic = responseObject[KABGlobalJsonKeyResult];
            str = ([dic[@"result_code"] integerValue] == 1) ? @"支付成功" : @"支付失败";
        }
        MBProgressHUD *temp = [MBProgressHUD showPromptWithAutoHideInView:self.view message:str];
        temp.completionBlock = ^(){
            [self payResultProcess];
        };
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [hud hideAnimated:NO];
        NSLog(@"查询结果失败：%@", error);
        MBProgressHUD *temp = [MBProgressHUD showPromptWithAutoHideInView:self.view message:@"网络请求失败"];
        temp.completionBlock = ^(){
            [self payResultProcess];
        };
    }];
}
#pragma mark - getters and setters
- (MJRefreshNormalHeader *)mj_header {
    if (!_mj_header) {
        _mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(tableViewRefresh:)];
        _mj_header.lastUpdatedTimeLabel.hidden = YES;
    }
    return _mj_header;
}

- (MJRefreshAutoNormalFooter *)mj_footer {
    if (!_mj_footer) {
        _mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(tableViewRefresh:)];
        _mj_footer.automaticallyRefresh = NO;
        _mj_footer.automaticallyHidden = YES;
    }
    return _mj_footer;
}

- (NSArray<NSString *> *)titlesArray {
    if (!_titlesArray) {
        _titlesArray = @[@"全部", @"待付款", @"待发货", @"待收货", @"已完成", @"退货"];
    }
    return _titlesArray;
}

- (NSArray<NSNumber *> *)typeIndexArray {
    if (!_typeIndexArray) {
        _typeIndexArray = @[@(0), @(1), @(2), @(3), @(4), @(5)];
    }
    return _typeIndexArray;
}

@end
